package dataTypes;

import exception.DataLengthException;

/**
 * A class for storing sequence data with corresponding qualities.
 * 
 * @author Christian Johansen
 * 
 */

public class PyroData implements ISequenceData {
	private String seqName;
	private int seqLength;
	private double x;
	private double y;
	private byte[] seqData;
	private byte[] seqQuality;
	private int rank;

	/**
	 * @param seqName
	 *            name of the sequence
	 * @param seqLength
	 *            length of the sequence
	 * @param x
	 *            x coordinate of the array on which the sequence was sequenced.
	 * @param y
	 *            coordinate of the array on which the sequence was sequenced.
	 * @param seqData
	 *            the actual sequence.
	 * @param seqQuality
	 *            quality of the sequence in Phred values.
	 * @param rank
	 *            rank of the sequence.
	 * @throws DataLengthException
	 *             if the <code>seqLength</code> doesn't match the length of
	 *             <code>seqData</code> and <code>seqQuality</code>.
	 */
	public PyroData(String seqName, int seqLength, double x, double y,
			byte[] seqData, byte[] seqQuality, int rank)
			throws DataLengthException {
		if (seqLength != seqData.length || seqLength != seqQuality.length) {
			throw new DataLengthException(
					"The length of the data does not match the given length.\n"
							+ "Given length " + seqLength + ", data length "
							+ seqData.length + ", quality length "
							+ seqQuality.length + ".");
		}
		this.seqName = seqName;
		this.seqLength = seqLength;
		this.x = x;
		this.y = y;
		this.rank = rank;
		this.seqData = seqData;
		this.seqQuality = seqQuality;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		String header = "Name: " + seqName + " rank: " + rank + " x: " + x
				+ " y: " + y + " length: " + seqLength;
		String quality = "";
		String sequence = "";
		for (int i = 0; i < seqLength; i++) {
			quality += seqQuality[i] + " ";
			sequence += (char) seqData[i] + " ";
			if (seqQuality[i] >= 10) {
				sequence += " ";
			}
		}

		return header + "\n" + quality + "\n" + sequence;
	}

	/* (non-Javadoc)
	 * @see dataTypes.ISequenceData#getSeqName()
	 */
	public String getSeqName() {
		return seqName;
	}

	/* (non-Javadoc)
	 * @see dataTypes.ISequenceData#getSeqLength()
	 */
	public int getSeqLength() {
		return seqLength;
	}

	/* (non-Javadoc)
	 * @see dataTypes.ISequenceData#getXCoordinate()
	 */
	public double getXCoordinate() {
		return x;
	}

	/* (non-Javadoc)
	 * @see dataTypes.ISequenceData#getYCoordinate()
	 */
	public double getYCoordinate() {
		return y;
	}

	/* (non-Javadoc)
	 * @see dataTypes.ISequenceData#getSeqData()
	 */
	public byte[] getSeqData() {
		return seqData;
	}

	/* (non-Javadoc)
	 * @see dataTypes.ISequenceData#getSeqQuality()
	 */
	public byte[] getSeqQuality() {
		return seqQuality;
	}

	/* (non-Javadoc)
	 * @see dataTypes.ISequenceData#getRank()
	 */
	public int getRank() {
		return rank;
	}
}
